package com.tin.util;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author liming_oicq@163.com
 * @date 2018-10-14 15:08
 */
public class DateUtil {

    public static void main(String[] args){
        String s = DateUtil.format(new Date());
        System.out.println(s);
    }

    public static String format(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(date);
    }

    public static Date parse(String s) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = null;
        try {
            date = sdf.parse(s);
        } catch ( ParseException e) {
            e.printStackTrace();
        }
        return date;
    }
}
